package com.crm.business.crm.mapper;


import com.crm.common.crm.common.CrmModel;
import com.crm.common.crm.entity.BO.CrmDataCheckBO;
import com.crm.common.crm.entity.BO.CrmRoiPutinPageBO;
import com.crm.common.crm.entity.BO.CrmRoiSearchBO;
import com.crm.common.crm.entity.PO.CrmField;
import com.crm.common.crm.entity.PO.CrmLeads;
import com.crm.common.crm.entity.PO.CrmTmkLeads;
import com.crm.common.crm.entity.VO.CrmDataCheckVO;
import com.crm.common.crm.entity.VO.CrmLeadsRoiStatisVO;
import com.crm.common.crm.entity.VO.CrmLeadsVO;
import com.crm.common.ka.core.feign.crm.entity.CrmEventBO;
import com.crm.business.servlet.BaseMapper;
import org.apache.ibatis.annotations.Param;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 线索表 Mapper 接口
 * </p>
 *
 * @author zhangzhiwei
 * @since 2020-05-21
 */
public interface CrmLeadsMapper extends BaseMapper<CrmLeads> {
    /**
     * 通过id查询线索数据
     *
     * @param id id
     * @param userId 用户ID
     * @return data
     */
    public CrmModel queryById(@Param("id") Integer id, @Param("userId") Long userId);

    List<String> eventLeads(@Param("data") CrmEventBO crmEventBO);

    List<Integer> eventLeadsList(@Param("userId") Long userId, @Param("time") Date time);

    String getNextNo(@Param("dateStr") String dateStr);

    List<CrmDataCheckVO> dataCheck(@Param("data") CrmDataCheckBO dataCheckBO);

    /**
     * 有效表单数
     * @return
     */
    Integer validDataNum(@Param("laiyuan") String laiyuan, @Param("qishu") String qishu);

    /**
     * 加客服数量
     * @param laiyuan
     * @param qishu
     * @return
     */
    Integer addCustomerServiceNum(@Param("laiyuan") String laiyuan, @Param("qishu") String qishu);

    /**
     * 小额报课数量
     * @param laiyuan
     * @param qishu
     * @return
     */
    Integer addClassReportNum(@Param("laiyuan") String laiyuan, @Param("qishu") String qishu);

    List<CrmLeadsVO> selectCrmLeadsCount(List<Integer> ids);
    List<CrmLeadsVO> selectCrmLeadsByList(List<Integer> ids);



    public CrmLeads queryLeadsDataBySerialNumber(String serialNumber);

    public CrmLeads queryLeadsDataByLeadsId(@Param("id") Integer id);

    public List<CrmLeads> queryTelephoneUniqueList(@Param("telephone") String telephone);
    public List<CrmLeads> queryWechatUniqueList(@Param("wechat") String wechat);

    public List<CrmLeads> queryByIds(List<Integer> ids);

    Integer queryLeadsWechatDataByData(@Param("wechat") String wechat);

    Integer queryLeadsTelephoneDataByData(@Param("telephone") String telephone);

    public List<CrmTmkLeads> queryTmkLeads(@Param("data") CrmRoiSearchBO search);

    public int updateAddWechatTimeIsNull(@Param("id") Integer id);

    public int updateSignClassTimeIsNull(@Param("id") Integer id);

    public int updateTransform(@Param("id") Integer id);

    /**
     * 根据Ids获取数据
     * @param ids
     * @return
     */
    List<CrmLeads> queryDataCountByLeadsId(List<Integer> ids);

    List<CrmLeads> queryLeadsCountByData(@Param("ownerUserId") Long ownerUserId, @Param("telephoneList") List<String> telephoneList, @Param("wechatList") List<String> wechatList);
    List<CrmLeads> queryLeadsCountByTelephoneData(@Param("ownerUserId") Long ownerUserId, @Param("telephoneList") List<String> telephoneList);
    List<CrmLeads> queryLeadsCountByWechatData(@Param("ownerUserId") Long ownerUserId, @Param("wechatList") List<String> wechatList);

    List<CrmLeadsRoiStatisVO> queryRoiStatis(@Param("startDate") String startDate, @Param("endDate") String endDate);

    List<Map<String, Long>> queryAllLeadsStatis(@Param("startDate") String startDate, @Param("endDate") String endDate);

    Integer queryLeadsStatisForSource(@Param("data") CrmRoiPutinPageBO data);

    List<CrmLeadsRoiStatisVO> queryLeadsAndCustomerStatisForData(@Param("putinPlatform") String putinPlatform,@Param("startDate") String startDate, @Param("endDate") String endDate);

    List<CrmLeadsRoiStatisVO> queryLeadsStatisForData(@Param("putinPlatform") String putinPlatform,@Param("startDate") String startDate, @Param("endDate") String endDate, @Param("userIdList") List<Long> userIdList);

}
